package com.ruoyi.appService.information.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.appService.information.domain.ZInformation;
import com.ruoyi.appService.information.service.IZInformationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 信息Controller
 * 
 * @author yuqihe
 * @date 2025-04-19
 */
@RestController
@RequestMapping("/information/information")
public class ZInformationController extends BaseController
{
    @Autowired
    private IZInformationService zInformationService;

    /**
     * 查询信息列表
     */
    @PreAuthorize("@ss.hasPermi('information:information:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZInformation zInformation)
    {
        startPage();
        List<ZInformation> list = zInformationService.selectZInformationList(zInformation);
        return getDataTable(list);
    }

    /**
     * 导出信息列表
     */
    @PreAuthorize("@ss.hasPermi('information:information:export')")
    @Log(title = "信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZInformation zInformation)
    {
        List<ZInformation> list = zInformationService.selectZInformationList(zInformation);
        ExcelUtil<ZInformation> util = new ExcelUtil<ZInformation>(ZInformation.class);
        util.exportExcel(response, list, "信息数据");
    }

    /**
     * 获取信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('information:information:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zInformationService.selectZInformationById(id));
    }

    /**
     * 新增信息
     */
    @PreAuthorize("@ss.hasPermi('information:information:add')")
    @Log(title = "信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZInformation zInformation)
    {
        return toAjax(zInformationService.insertZInformation(zInformation));
    }

    /**
     * 修改信息
     */
    @PreAuthorize("@ss.hasPermi('information:information:edit')")
    @Log(title = "信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZInformation zInformation)
    {
        return toAjax(zInformationService.updateZInformation(zInformation));
    }

    /**
     * 删除信息
     */
    @PreAuthorize("@ss.hasPermi('information:information:remove')")
    @Log(title = "信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zInformationService.deleteZInformationByIds(ids));
    }


    @Anonymous
    @GetMapping("/getText/{id}")
    public AjaxResult getText(@PathVariable("id") Long id)
    {
        if (id == null || id <= 0) {
            return error("Invalid ID");
        }
        return  success(zInformationService.getText(id));
    }

    @GetMapping("/getKnowledge")
    public TableDataInfo getKnowledge(ZInformation zInformation)
    {
        List<ZInformation> list = zInformationService.selectZInformationList(zInformation);
        return getDataTable(list);
    }
}
